package com.example.amusic.service

import androidx.lifecycle.MutableLiveData
import androidx.media3.common.Player

object PlayServiceModule {

    private var player: Player? = null
    private var playerController: PlayerController? = null

    private val _isPlayerReady = MutableLiveData(false)
    val isPlayerReady = _isPlayerReady

    fun setPlayer(player: Player) {
        this.player = player
        _isPlayerReady.value = true
    }

    fun initPlayController(): PlayerController {
        return playerController ?: run {
            val player = player ?: throw IllegalStateException("Player not prepared!")
            PlayerControllerImpl(player).also {
                playerController = it
            }
        }
    }
}